<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class RegisterApiController extends AbstractRestfulController
{
    public function getList()
    {	
		$dictionaryTable=$this->getServiceLocator()->get('Models\Model\UserdetailesFactory');	
		$getDictionarylist = $dictionaryTable->getdictionarylist()->toarray();	
		if(count($getDictionarylist)!=0){
			return new JsonModel(array(
				'dictionaryList'	=> json_encode($getDictionarylist),
				'value' 			=> 1,
			));			
		}else{
			return new JsonModel(array(
				'value'		 => 0,
				'data'  	 => 'No Data',
			));			
		}
    }
    public function get($data)
    {
		header('Access-Control-Allow-Origin: *');		
		$userDetailesTable=$this->getServiceLocator()->get('Models\Model\UserdetailesFactory');
		$values=explode('-',$data);
		$checkSCDStatus = $userDetailesTable->checkSCDStatus($values)->toarray();
		if(count($checkSCDStatus)!=0){
			return new JsonModel(array(
				'checkStatus' 		=> json_encode($checkSCDStatus),
				'value' 			=> 0,
			));			
		}else{
			return new JsonModel(array(
				'value' 	=> 1,
			));			
		}
    }
    public function create($data)
    {
		header('Access-Control-Allow-Origin: *');	
		$userDetailesTable=$this->getServiceLocator()->get('Models\Model\UserdetailesFactory');
		$checkImeiNumber=$userDetailesTable->checkImeiNumber($data['imei_number'])->toArray();
		if(count($checkImeiNumber)!=0){
			$userDetailes=$userDetailesTable->updateUserDetailes($data['imei_number']);
		}else{
			$userDetailes=$userDetailesTable->registerDetailes($data);
		}
		if(count($userDetailes)!=0){
			return new JsonModel(array(
				'status'		=>	'success',
				'user_id'		=>	$userDetailes,
				'value'			=>	1,
			));	
		}else{
			return new JsonModel(array(
				'status'	=>	'fail',
				'value'		=>   0,
			));			
		}
	}
    public function update($imei_number, $data)
    {
        header('Access-Control-Allow-Origin: *');	
		$userDetailesTable=$this->getServiceLocator()->get('Models\Model\UserdetailesFactory');
		$getUserInfo=$userDetailesTable->checkImeiNumber($imei_number)->toArray();
			return new JsonModel(array(
				'status'		=>	'success',
				'Ucstatus'		=>	json_encode($getUserInfo),
				'value'			=>	1,
			));	
    }
    public function delete($id)
    {
       
    }
}